package com.iwuke.dance.wallet.starlight_value;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.GlideUtil;
import com.iwuke.dance.util.ToastUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;

import java.util.HashMap;
import java.util.Map;

import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/9/22
 * 活动明细
 */
public class EventDetailsActivity extends BaseActivity implements View.OnClickListener {

    private TitleBarView title_bar;
    private ImageView img_event_income;
    private TextView tv_starlight_value;
    private TextView tv_status;
    private TextView tv_get_gift;
    private TextView tv_get_starlight_value;
    private TextView tv_get_time;
    private TextView tv_giver;
    private TextView tv_reward_time;
    private TextView tv_event_name;
    private TextView tv_event_time;
    private StarlightTransactionRecordHomepageBean data;

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(EventDetailsActivity.this,networkEvent,title_bar);

    }

    @Override
    protected int getView() {
        return R.layout.activity_event_details;
    }

    @Override
    protected void init(View mView) {

        title_bar = findViewById(R.id.title_bar);
        //活动图片
        img_event_income = findViewById(R.id.img_event_income);
        //星光值
        tv_starlight_value = findViewById(R.id.tv_starlight_value);
        //当前状态
        tv_status = findViewById(R.id.tv_status);
        //获得礼物
        tv_get_gift = findViewById(R.id.tv_get_gift);
        //获取星光值
        tv_get_starlight_value = findViewById(R.id.tv_get_starlight_value);
        //获取时间
        tv_get_time = findViewById(R.id.tv_get_time);
        //打赏人
        tv_giver = findViewById(R.id.tv_giver);
        //奖励时间
        tv_reward_time = findViewById(R.id.tv_reward_time);
        //活动名称
        tv_event_name = findViewById(R.id.tv_event_name);
        //活动时间
        tv_event_time = findViewById(R.id.tv_event_time);

        title_bar.setLeftOnClick(this);
        title_bar.setTitleText("活动收益明细");

    }

    @Override
    protected void initData() {

        data = Util.getSerializableSafe(getIntent(), "data", StarlightTransactionRecordHomepageBean.class);


        requestEventDetails();

    }

    private void requestEventDetails() {
        Map<String, String> map = new HashMap<>();
        map.put("transactionRecordId", String.valueOf(data.id));

        PathUrl.getTransactionRecord(map, new PathUrl.DataCallBack<StarlightTransactionRecordHomepageBean>() {
            @Override
            public void onSucess(StarlightTransactionRecordHomepageBean bean) {

                if (bean!=null){

                    //活动图片
                    if (!TextUtils.isEmpty(bean.iconUrl)){
                        GlideUtil.setImageView(EventDetailsActivity.this,bean.iconUrl,img_event_income);
                    }else {
                        GlideUtil.setImageView(EventDetailsActivity.this,R.mipmap.img_live,img_event_income);
                    }



                    //星光值
                    tv_starlight_value.setText("+"+bean.totalPrice+"星光值");
                    switch (bean.status){
                        case 1:
                            //当前状态 "已获取"
                            tv_status.setText("已获取");
                            break;

                        case 0:
                        case 2:
                            tv_status.setText("未获取");
                            break;
                    }
                    //获得礼物
                    tv_get_gift.setText("小心心 x"+bean.num);
                    //获取星光值
                    tv_get_starlight_value.setText(String.valueOf(bean.totalPrice));
                    //获取时间
                    tv_get_time.setText(bean.createTime);
                    //打赏人
                    tv_giver.setText(bean.relatedUserName);
                    //奖励时间
                    tv_reward_time.setText(bean.createTime);
                    //活动名称 青少年街舞大赛
                    tv_event_name.setText(bean.activityName);
                    //活动时间
                    tv_event_time.setText(bean.activityStartTime+"至\n"+bean.activityEndTime);

                }

            }

            @Override
            public void onFail(String errorCode) {
                ToastUtil.setToast(EventDetailsActivity.this,errorCode);
            }
        });

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){
            finish();
        }
    }
}
